package com.mh.domain;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.map.annotate.JsonDeserialize;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.hibernate.validator.constraints.NotEmpty;

import com.mh.web.utils.DateJsonDeserializer;
import com.mh.web.utils.DateJsonSerializer;

/**
 * 
 * @ModelCoreReference [platform:/resource/demo-mh/.springDSL/com/mh/domain/Product.datatype]
 */

@Entity
@NamedQueries({
		@NamedQuery(name = "findAllProducts", query = "select myProduct from Product myProduct"),
		@NamedQuery(name = "findProductByCreatedBy", query = "select myProduct from Product myProduct where myProduct.createdBy = ?1"),
		@NamedQuery(name = "findProductByCreatedByContaining", query = "select myProduct from Product myProduct where myProduct.createdBy like ?1"),
		@NamedQuery(name = "findProductByCreatedOn", query = "select myProduct from Product myProduct where myProduct.createdOn = ?1"),
		@NamedQuery(name = "findProductById", query = "select myProduct from Product myProduct where myProduct.id = ?1"),
		@NamedQuery(name = "findProductByModifiedBy", query = "select myProduct from Product myProduct where myProduct.modifiedBy = ?1"),
		@NamedQuery(name = "findProductByModifiedByContaining", query = "select myProduct from Product myProduct where myProduct.modifiedBy like ?1"),
		@NamedQuery(name = "findProductByModifiedOn", query = "select myProduct from Product myProduct where myProduct.modifiedOn = ?1"),
		@NamedQuery(name = "findProductByName", query = "select myProduct from Product myProduct where myProduct.name = ?1"),
		@NamedQuery(name = "findProductByNameContaining", query = "select myProduct from Product myProduct where myProduct.name like ?1"),
		@NamedQuery(name = "findProductByPrice", query = "select myProduct from Product myProduct where myProduct.price = ?1"),
		@NamedQuery(name = "findProductByPrimaryKey", query = "select myProduct from Product myProduct where myProduct.id = ?1") })
@Table(schema = "MHTEST", name = "PRODUCT")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "demo-mh/com/mh/domain", name = "Product")
@XmlRootElement(namespace = "demo-mh/com/mh/domain")
public class Product implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 */

	@Column(name = "ID", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@Id
	@XmlElement
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq_product")
	@SequenceGenerator(name = "seq_product", sequenceName = "seq_product")
	Integer id;

	/**
	 */

	@Column(name = "NAME", length = 60, nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	@NotNull
	@NotEmpty
	@Size(max=60,  message="{com.vit.tamanho.maximo}")
	String name;

	/**
	 */

	@Column(name = "PRICE", scale = 2, precision = 16, nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	@NotNull
	Double price;

	/**
	 */

	@Column(name = "CREATED_BY", length = 30, nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	@NotNull
	@NotEmpty
	String createdBy;

	/**
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "CREATED_ON", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	@NotNull
	Date createdOn;

	/**
	 */

	@Column(name = "MODIFIED_BY", length = 30)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String modifiedBy;

	/**
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "MODIFIED_ON")
	@Basic(fetch = FetchType.EAGER)
	Date modifiedOn;

	/**
	 */
	@OneToMany(mappedBy = "product", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)
	@XmlElement(name = "", namespace = "")
	java.util.Set<com.mh.domain.Item> items;

	/**
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 */

	public Integer getId() {
		return this.id;
	}

	/**
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 */
	public String getName() {
		return this.name;
	}

	/**
	 */
	public void setPrice(Double price) {
		this.price = price;
	}

	/**
	 */
	public Double getPrice() {
		return this.price;
	}
	
	

	/**
	 */
	public void setCreatedBy(String createdBy) {
		this.createdBy = createdBy;
	}

	/**
	 */
	public String getCreatedBy() {
		return this.createdBy;
	}

	/**
	 */
	@JsonDeserialize(using=DateJsonDeserializer.class)
	public void setCreatedOn(Date createdOn) {
		this.createdOn = createdOn;
	}

	/**
	 */
	@JsonSerialize(using=DateJsonSerializer.class)
	public Date getCreatedOn() {
		return this.createdOn;
	}

	/**
	 */
	public void setModifiedBy(String modifiedBy) {
		this.modifiedBy = modifiedBy;
	}

	/**
	 */
	public String getModifiedBy() {
		return this.modifiedBy;
	}

	/**
	 */
	@JsonDeserialize(using=DateJsonDeserializer.class)
	public void setModifiedOn(Date modifiedOn) {
		this.modifiedOn = modifiedOn;
	}

	/**
	 */
	@JsonSerialize(using=DateJsonSerializer.class)
	public Date getModifiedOn() {
		return this.modifiedOn;
	}

	/**
	 */
	public void setItems(Set<Item> items) {
		this.items = items;
	}

	/**
	 */
	@JsonIgnore
	public Set<Item> getItems() {
		if (items == null) {
			items = new java.util.LinkedHashSet<com.mh.domain.Item>();
		}
		return items;
	}

	/**
	 */
	public Product() {
	}

	/**
	 * Copies the contents of the specified bean into this bean.
	 *
	 */
	public void copy(Product that) {
		setId(that.getId());
		setName(that.getName());
		setPrice(that.getPrice());
		setCreatedBy(that.getCreatedBy());
		setCreatedOn(that.getCreatedOn());
		setModifiedBy(that.getModifiedBy());
		setModifiedOn(that.getModifiedOn());
		setItems(new java.util.LinkedHashSet<com.mh.domain.Item>(that.getItems()));
	}

	/**
	 * Returns a textual representation of a bean.
	 *
	 */
	public String toString() {

		StringBuilder buffer = new StringBuilder();

		buffer.append("id=[").append(id).append("] ");
		buffer.append("name=[").append(name).append("] ");
		buffer.append("price=[").append(price).append("] ");
		buffer.append("createdBy=[").append(createdBy).append("] ");
		buffer.append("createdOn=[").append(createdOn).append("] ");
		buffer.append("modifiedBy=[").append(modifiedBy).append("] ");
		buffer.append("modifiedOn=[").append(modifiedOn).append("] ");

		return buffer.toString();
	}

	/**
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = (int) (prime * result + ((id == null) ? 0 : id.hashCode()));
		return result;
	}

	/**
	 */
	public boolean equals(Object obj) {
		if (obj == this)
			return true;
		if (!(obj instanceof Product))
			return false;
		Product equalCheck = (Product) obj;
		if ((id == null && equalCheck.id != null) || (id != null && equalCheck.id == null))
			return false;
		if (id != null && !id.equals(equalCheck.id))
			return false;
		return true;
	}
}
